package com.nxk.modules.content.web;

import com.nxk.modules.content.entity.ConNews;
import com.nxk.modules.content.service.ConNewsService;
import com.nxk.modules.exception.ResultEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/a/content/news")
public class ConNewsController {
    
       
    @Autowired
    private ConNewsService conNewsService;


    /**
     * 保存数据接口
     *
     * @param conConNews
     * @return
     */
    @RequiresPermissions("content:news:edit")
    @PutMapping("/save")
    public ResultEntity save(@Validated ConNews conConNews) {
        boolean save = conNewsService.save(conConNews);
        return save ? ResultEntity.success(conNewsService.getById(conConNews.getId())) : ResultEntity.fail();
    }


    /**
     * 更新数据接口
     *
     * @param conConNews
     * @return
     */
    @RequiresPermissions("content:news:edit")
    @PostMapping("/update")
    public ResultEntity update(@Validated ConNews conConNews) {
        boolean save = conNewsService.save(conConNews);
        return save ? ResultEntity.success(conNewsService.getById(conConNews.getId())) : ResultEntity.fail();
    }


    /**
     * 修改数据状态接口
     *
     * @param conConNews
     * @return
     */
    @RequiresPermissions("content:news:edit")
    @PostMapping("/updateStatus")
    public ResultEntity updateStatus(ConNews conConNews) {
        boolean save = conNewsService.save(conConNews);
        return save ? ResultEntity.success(conNewsService.getById(conConNews.getId())) : ResultEntity.fail();
    }


    /**
     * 根据id获取单条数据接口
     *
     * @param conConNews
     * @return
     */
    @RequiresPermissions("content:news:view")
    @GetMapping("/get")
    public ResultEntity get(ConNews conConNews) {
        return ResultEntity.success(conNewsService.getById(conConNews.getId()));
    }


    /**
     * 查询分页数据接口
     *
     * @param conConNews
     * @return
     */
    @RequiresPermissions("content:news:view")
    @PostMapping("list")
    public ResultEntity list(ConNews conConNews) {
        return ResultEntity.success(conNewsService.page(conConNews));
    }

    /**
     * 根据id物理删除数据接口
     *
     * @param conConNews
     * @return
     */
    @RequiresPermissions("content:news:edit")
    @DeleteMapping("delete")
    public ResultEntity delete(ConNews conConNews) {
        boolean delete = conNewsService.deleteById(conConNews.getId());
        return delete ? ResultEntity.success() : ResultEntity.fail();
    }
    
}
